home *** CD-ROM | disk | FTP | other *** search
/ LineOne ISP Sign-Up 5 / LineOne.iso / assets / cxt / scripts / parentScripts.cst / 00013_errorManager parent.ls < prev    next >
Encoding:
Text File  |  2001-01-27  |  3.3 KB  |  109 lines

  1. -- 2000.02.26
  2. -- Clive Green <clivegreen@atlas.co.uk>
  3.  
  4. ------------------------------------------------------------------------------------------------------
  5.  
  6. -- This parent script creates an object and assigns it to a Lingo property called the alertHook -
  7. -- so named because it provides a way to capture Lingo error alerts.
  8.  
  9. ------------------------------------------------------------------------------------------------------
  10.  
  11. -- declare properties:
  12. property main   -- main code object
  13. property errors -- a list of error codes with messages
  14.  
  15. ------------------------------------------------------------------------------------------------------
  16.  
  17. on new me,L
  18.   
  19.   -- (1) extract and check arguments:
  20.   
  21.   -- check for a parameter list:
  22.   if ilk(L) <> #propList then return [#error:#noParamListSupplied, #msg:"errorManager:new"]
  23.   
  24.   -- a reference to the parent codebase is REQUIRED:
  25.   main = L[#main]
  26.   if (ilk(main) <> #instance) then return [#error:#noMainObjectSupplied, #msg:"errorManager:new"]
  27.   
  28.   --------------------
  29.   
  30.   -- (2) obtain listing of error messages:
  31.   dm = main.getDataManager()
  32.   eL = dm.getData([set:#errorListing])
  33.   
  34.   -- confirm listing was obtained:
  35.   if ilk(eL) <> #propList then return [#error:#noErrorListingObtained, #msg:"errorManager:new"] 
  36.   errors = eL
  37.   
  38.   --------------------
  39.   
  40.   -- (3) divert error messages from Lingo:
  41.   me.setAlertHook(1)
  42.   
  43.   --------------------
  44.   
  45.   -- just pass back my address:
  46.   return me
  47.   
  48.   ----------------------------------------------------------------------------------------------------
  49.   
  50. on setAlertHook me,n
  51.    
  52.   -- set/cancel lingo error alert diversion according to the toggle value passed:
  53.   if n = 1 then v = me
  54.   else v = 0
  55.   
  56.   the alertHook = v
  57.   
  58.   ----------------------------------------------------------------------------------------------------
  59.   
  60. on error me,eL
  61.   
  62.   -- eL represents an error data package - extract and check its elements:
  63.   if ilk(eL) <> #propList then eL = [#error:#e1001]
  64.   
  65.   -- attempt obtain errorCode symbol and message:
  66.   e = eL[#error]
  67.   m = eL[#msg]
  68.   if voidP(e) then e = #e1002
  69.   else if not symbolP(e) then e = #e1003
  70.   
  71.   -- attempt to extract the data for errorCode e:
  72.   dL = errors[e]
  73.   
  74.   -- if no data for error e was listed, use the errorCode supplied as the error name, with message
  75.   -- (if any )supplied:
  76.   if ilk(dL) <> #propList then dL = [#error:e, #msg:m]
  77.   
  78.   -- extract errorName:
  79.   n = dL[#error]
  80.   
  81.   -- only use native message for error e (if any) when no msg string has been explicitly supplied:
  82.   if not stringP(m) then m = dL[#msg]
  83.   
  84.   -- the errorCode and errorName will match if the former wasn't a listed error;
  85.   --if so, amend the error code to indicate this:
  86.   if e = n then e = #applicationError
  87.   
  88.   -------------------- 
  89.   
  90.   -- combine the errorCode and errorName:
  91.   e = "#" & e & ": #" & n
  92.   
  93.   -- pass this information to my alertHook handler:
  94.   return me.alertHook(e,m)
  95.   
  96.   ----------------------------------------------------------------------------------------------------
  97.   
  98. on alertHook me,e,m
  99.   
  100.   -- VERY rudimentary lingo error handling -
  101.   -- this is primarily intended to avoid lingo alerts: 
  102.   
  103.   -- put your error handling code here:
  104.   put e & RETURN & m
  105.   
  106.   -- pretend everything is lovely ...
  107.   return 1
  108.   
  109.   ----------------------------------------------------------------------------------------------------